package com.hzp.day51.dao;

import com.hzp.day51.model.Employee;
import com.hzp.day51.util.RedisCache;

import java.util.List;

import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mybatis.spring.annotation.MapperScan;

@MapperScan
@CacheNamespace(implementation=com.hzp.day51.util.RedisCache.class)
public interface EmployeeMapper {
    @Delete({
        "delete from employee",
        "where emp_id = #{empId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer empId);
    
    @Insert({
        "insert into employee (emp_id, emp_name, ",
        "emp_age, emp_sex, ",
        "emp_tel, pos_id)",
        "values (#{empId,jdbcType=INTEGER}, #{empName,jdbcType=VARCHAR}, ",
        "#{empAge,jdbcType=VARCHAR}, #{empSex,jdbcType=VARCHAR}, ",
        "#{empTel,jdbcType=VARCHAR}, #{pos.posId,jdbcType=INTEGER})"
    })
    int insert(Employee record);

    int insertSelective(Employee record);
    
    
    @Select({
        "select",
        "emp_id, emp_name, emp_age, emp_sex, emp_tel, pos_id",
        "from employee order by emp_id desc",
    })
    @ResultMap("com.hzp.day51.dao.EmployeeMapper.BaseResultMap")
    List<Employee> selectAll();
    
    @Select({
        "select",
        "emp_id, emp_name, emp_age, emp_sex, emp_tel, pos_id",
        "from employee",
        "where emp_id = #{empId,jdbcType=INTEGER}"
    })
    @ResultMap("com.hzp.day51.dao.EmployeeMapper.BaseResultMap")
    Employee selectByPrimaryKey(Integer empId);

    int updateByPrimaryKeySelective(Employee record);

    @Update({
        "update employee",
        "set emp_name = #{empName,jdbcType=VARCHAR},",
          "emp_age = #{empAge,jdbcType=VARCHAR},",
          "emp_sex = #{empSex,jdbcType=VARCHAR},",
          "emp_tel = #{empTel,jdbcType=VARCHAR},",
          "pos_id = #{pos.posId,jdbcType=INTEGER}",
        "where emp_id = #{empId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Employee record);
}